package cn;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

//代表socket里的服务器端
public class Server {
    public static void main(String[] args) throws IOException {
        //1,开启服务器 -- 参数是端口号0~65535
        ServerSocket s=new ServerSocket(8000);
        System.out.println("服务器已开启!!");

        //2,接收客户端发来的请求
        Socket a=s.accept();
        System.out.println("接收到了   客户端的连接!!");

        //3,读取客户端发来的hello
        InputStream i=a.getInputStream();
        for (int j = 0; j < 5; j++) {
            char x= (char) i.read();//默认返回int类型->char
            System.out.println(x);
        }
        //i.close();

        //4,给客户端写出数据jack
        OutputStream o=a.getOutputStream();
        o.write("jack".getBytes());
        o.close();


    }
}
